﻿#include "stdafx.h"
#include "AstInc.h"
#include "SIntegerType.h"
#include "CodeGenerate/BinaryGen.h"
#include "CodeGenerate/ValueGen.h"
#include "CodeGenerate/LetGen.h"

using namespace llvm;
extern LLVMContext llvmContext;
CodeGen * AstInc::makeGen(SiContext * parent)
{
	auto l = expr->makeGen(parent);
	auto tp = IntegerType::getInt64Ty(llvmContext);
	auto value = ConstantInt::getSigned(tp, isInc ? 1 : -1);
	auto r = new ValueGen(SIntegerType::get(64), value);

	auto *p = new BinaryGen('+', l, r);
	
	auto *x = new LetGen();
	x->left = l;
	x->right = p;
	return x;
}

void AstInc::draw(std::ostream & os)
{
	dotLable(os, isInc ? "++" : "--");
	dotPointTo(os, expr);
}
